package edu.upe.poli.dsc.sd.mensagem;
import java.net.InetAddress;
import java.net.UnknownHostException;

	
public class Id {
	
	private InetAddress host;
	private int port;
	
	public Id(String host, int port) {
		
		try {
			this.host = InetAddress.getByName(host);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		this.port = port;
	}
	
	public int hashCode() {
		return (getHost().hashCode() + getPort()) * 10000;
	}
	
	public boolean equals(Object obj) {
		
		if(obj instanceof Id == false)
			return false;
		
		Id id = (Id) obj;
		
		return this.getHost().getHostAddress().equals(id.getHost().getHostAddress()) && this.getPort() == id.getPort();
	}
	
	public String toString() {
		return getHost().getHostAddress() + ":" + this.getPort();
	}
	
	public InetAddress getHost() {
		return host;
	}

	public void setHost(InetAddress host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}
	
}
